// /*
//  * @Author: WanYiMing
//  * @Date:2024-07-01-17:27
//  * @Description:
//  */

using System.Collections.Generic;
using Code.GameLogic.XianJian.Element.JianQiAction;
using UnityEngine;

namespace Code.GameLogic.XianJian.Element
{
    public class JianQiController : MonoBehaviour
    {
        public GameObject jianQiPrefab;

        // 在类外部定义速度
        public float speed = 10f;

        public int pollSize = 100;

        private JianQiPoll _jianQiPoll;

        private Dictionary<string, AbsJianQiAction> _jianQiActions;
        
        
        
        public void InitController(string path)
        {
            jianQiPrefab = Resources.Load<GameObject>(path);
            _jianQiPoll = new JianQiPoll(jianQiPrefab, gameObject, pollSize, Instantiate);
            _jianQiActions = new Dictionary<string, AbsJianQiAction>();
            _jianQiActions["ActionLocking"] = new ActionLocking();
            _jianQiActions["ActionSpaceLine"] = new ActionSpaceLine();
        }


        public void ActiveBehaviour(GameObject target,string actionCode)
        {
            GameObject jianQi = _jianQiPoll.GetJianQi();
            JianQiBehaviour jianQiBehaviour = jianQi.AddComponent<JianQiBehaviour>();
            jianQiBehaviour.ActiveBehaviour(HitTarget, target, speed, _jianQiActions[actionCode]);
        }


        private void HitTarget(GameObject jianQi)
        {
            _jianQiPoll.ReleaseJianQi(jianQi);
            //todo 计算伤害
        }
    }
}